// api/weatherApi.js

const fetchWeatherData = async () => {
  try {
    const response = await fetch("http://114.132.177.63/get_analog_data/");
    const rawData = await response.json();

    // 对数据进行处理，保留两位小数
    const formattedData = rawData.map(item => ({
      ...item,
      temperature: item.temperature !== null ? item.temperature.toFixed(2) : null,
      humidity: item.humidity !== null ? item.humidity.toFixed(2) : null,
      wind_speed: item.wind_speed !== null ? item.wind_speed.toFixed(2) : null,
      visibility: item.visibility !== null ? item.visibility.toFixed(2) : null,
      pressure: item.pressure !== null ? item.pressure.toFixed(2) : null
    }));

    return formattedData;
  } catch (error) {
    console.error("获取天气数据时出错:", error);
    throw error;
  }
};

export { fetchWeatherData };
